/*
  What is the probability of getting a pair in 6 cards from a standard
  deck?
*/
#include <vector>
#include <iostream>
#include <ext/algorithm>
#include <set>
#include <ext/numeric>

using namespace std;

typedef vector<unsigned> Cards;
template <class T> struct Mod13Inserter {
    T &t_; Mod13Inserter(T &t) : t_(t) {}
    void operator()( unsigned v ) { t_.insert(v%13); }
};
int main( int argc, char *argv[] ) {
    srand( time(NULL) );
    Cards deck(52); iota( deck.begin(), deck.end(), 0 );
    const unsigned iterations( 10000 );
    unsigned won = 0;
    for ( unsigned i = 0; i < iterations; i++ ) {
	Cards hand(6);
	random_sample( deck.begin(), deck.end(), hand.begin(), hand.end() );
	set<unsigned> check;
	for_each( hand.begin(), hand.end(), Mod13Inserter< typeof(check) >(check) );
	if ( check.size() < 6 ) { won++; }
    }
    cout << (double)won/iterations << endl;
    return 0;
}
